/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.airavata.metcat.dispatcher;

import java.util.HashMap;

import org.apache.airavata.metcat.parser.EventNotificationParser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class EventMsgHandlerMap {
	
	private HashMap<String,EventNotificationParser> map;
	public static EventMsgHandlerMap instance;
	
	private EventMsgHandlerMap() {

	}
	
	private static void init(){
		ApplicationContext context = new FileSystemXmlApplicationContext(ClassLoader.getSystemClassLoader().getResource("SpringBeans/SpringBeans.xml").toString());
		instance = (EventMsgHandlerMap) context.getBean("event-parser-beans-map");
	}
	
	public void addEventMsgHandler(String eventType, EventNotificationParser handler){
		map.put(eventType, handler);
	}
	
	public EventNotificationParser getEventMsgHandler(String eventType){
		return map.get(eventType);
	}
	
	public static EventMsgHandlerMap getInstance(){
		if(instance == null ){
			init();
		}
		return instance;
	}
	
	public void setMap(HashMap<String, EventNotificationParser> map) {
		this.map = map;
	}
}
